<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Salle
 *
 * @author Quentin
 */
class Salle implements JsonSerializable{
    private $machines = Array();
    private $infos = "";
    private $name = "";
    private $id = "";
    public function __construct($name, $infos, $machines = Array()){
        $this->machines = $machines;
        $this->name = $name;
        $this->infos = $infos;
    }
    public function __toString(){
        return "Salle[name='$this->name', machines='$this->machines']";
    }
    public function getId(){
        return $this->id;
    }
    public function setId($id){
        $this->id = $id;
    }
    public function getMachines(){
        return $this->machines;
    }
    public function setMachines($machines){
        $this->machines = $machines;
    }
    public function addMachine($machine){
       $this->machines[]=$machine;
    }
    public function getName(){
        return $this->name;
    }
    public function setName($name){
        $this->name;
    }
    public function getInfos(){
        return $this->infos;
    }
    public function setInfos($infos){
        $this->infos;
    }

    public function jsonSerialize() {
        $json = Array();
        $json["name"] = $this->name;
        $json["id"] = $this->id;
        $json["infos"] = $this->infos;
        $json["machines"] = $this->machines;
        return $json;
    }
    public function xmlSerialize($domtree){
        $xmlRoot = $domtree->createElement("salle");
        $name = $domtree->createElement("name", $this->name);
        $xmlRoot->appendChild($name);
        $id = $domtree->createElement("id", $this->id);
        $xmlRoot->appendChild($id);
        $infos = $domtree->createElement("infos", $this->infos);
        $xmlRoot->appendChild($infos);
        $machines = $domtree->createElement("machines");
        foreach($this->getMachines() as $machine){
            $machines->appendChild($machine->xmlSerialize($domtree));
        }
        $xmlRoot->appendChild($machines);
        return $xmlRoot;
    }
}

?>
